@using System.Web.WebPages.Scope;

@functions {

    private const string InitializedExceptionMessage = "The GetSatisfaction Helper has not been initialized. You should call the Initialize method.";
    private const string ArgumentNullExceptionMessage = "Argument cannot be null or empty.";
       
    private const string GetSatisfactionUrl = "";

    private static readonly object _companyNameKey = new object();    
    private static readonly object _initializedKey = new object();
        
    
    public static string CompanyName{
        get {
            if (!Initialized) {
                throw new InvalidOperationException(InitializedExceptionMessage);
            }
            return (string)(ScopeStorage.CurrentScope[_companyNameKey] ?? "");
        }

        private set {
            if (value == null) {
                throw new ArgumentNullException("CompanyName");
            }

            ScopeStorage.CurrentScope[_companyNameKey] = value;
        }
    }
    
    private static bool Initialized {
        get {
            return (bool)(ScopeStorage.CurrentScope[_initializedKey] ?? false);
        }
        set {
            ScopeStorage.CurrentScope[_initializedKey] = value;
        }
    }

    /// <summary>
    /// Initializes the GetSatisfaction helper.
    /// </summary>
    /// <param name="companyName">Your GetSatisfaction company name</param>    
    public static void Initialize(string companyName) {
        if (companyName.IsEmpty()) {
            throw new ArgumentException(ArgumentNullExceptionMessage, "companyName");
        }
        CompanyName = companyName;        

        Initialized = true;
    }
}

@*
Summary:
    Shows a GetSatisfaction Feedback tab widget.
    This method must be called at the bottom of the page. 

Optional parameters:

Parameter: type
    Specifies the default feedback type to display: idea (default), question, problem, praise
Parameter: placement
    Specifies the tab placement in the page: left (default), right, bottom, hidden
Parameter: color
    Specifies the hexadecimal color for the tab. Default value is #222 (gray).
*@

@helper GetFeedbackTabWidget(
                        string type = "idea",
                        string placement = "left",
                        string color = "#222") {
       
    <script type="text/javascript" charset="utf-8">
        var is_ssl = ("https:" == document.location.protocol);
        var asset_host = is_ssl ? "https://s3.amazonaws.com/getsatisfaction.com/" : "http://s3.amazonaws.com/getsatisfaction.com/";
        document.write(unescape("%3Cscript src='" + asset_host + "javascripts/feedback-v2.js' type='text/javascript'%3E%3C/script%3E"));
    </script>

    <script type="text/javascript" charset="utf-8">
        var feedback_widget_options = {};
        
        feedback_widget_options.display = "overlay";  
        feedback_widget_options.company = "@CompanyName";
        feedback_widget_options.placement = "@placement";
        feedback_widget_options.color = "@color";
        feedback_widget_options.style = "@type" ;
        var feedback_widget = new GSFN.feedback_widget(feedback_widget_options);
    </script>
}

@*
Summary:
    Shows a GetSatisfaction Feedback widget embedded on the page.
  
Parameter: type
    Specifies the default feedback type to display: idea (default), question, problem, praise.

*@
@helper GetFeedbackPageWidget(string type = "idea") {
    <script type="text/javascript" charset="utf-8">
        var is_ssl = ("https:" == document.location.protocol);
        var asset_host = is_ssl ? "https://s3.amazonaws.com/getsatisfaction.com/" : "http://s3.amazonaws.com/getsatisfaction.com/";
        document.write(unescape("%3Cscript src='" + asset_host + "javascripts/feedback-v2.js' type='text/javascript'%3E%3C/script%3E"));
    </script>

    <script type="text/javascript" charset="utf-8">
        var feedback_widget_options = {};
        feedback_widget_options.display = "inline"; 
        feedback_widget_options.company = "@CompanyName" ;   
        feedback_widget_options.style = "@type" ;
        
        var feedback_widget = new GSFN.feedback_widget(feedback_widget_options);
    </script>
}

@*
Summary:
    Shows a GetSatisfaction Topic list widget.

Optional parameters:

Parameter: type
	Specifies the feedback type to filter the list: idea, question, problem, praise.
Parameter: tag
    Specifies the topic tag to filter the list. 
Parameter: limit
    Specifies the max. quantity of topics that will be displayed in the widget. 
    Default value: 5
Parameter: cssList
    Specifies the css stylesheet for the list
Parameter: cssContent
    Specifies the css stylesheet fot the widget content

*@
@helper GetTopicWidget(
                    string type = "",
                    string tag = "",
                    int limit = 5,
                    string cssList = "gsfn_list_widget",
                    string cssContent = "gsfn_content",
                    string title = "Active customer service discussions") {
	
	var widget = "http://getsatisfaction.com/" + CompanyName + "/topics.widget?callback=gsfnTopicsCallback&amp;limit=" + limit.ToString() + "&amp;sort=last_active_at";

	if (!type.IsEmpty()) {
		 widget += "&amp;style='" + type + "'";
	}
	if (!tag.IsEmpty()) {
		 widget += "&amp;tag='" + tag + "'";
	}

    <div id='@cssList'>
        <a href="http://getsatisfaction.com/@CompanyName" class="widget_title">@title</a>
        <div id='@cssContent'>Loading...</div>
        <div>
            <a href="http://getsatisfaction.com/"><img alt="Burst16" src="http://getsatisfaction.com/images/burst16.png" style="vertical-align: middle;" /></a>
            <a href="http://getsatisfaction.com/">Get Satisfaction support network</a>
        </div>
    </div>

    <script src="http://getsatisfaction.com/@CompanyName/widgets/javascripts/7616e1eca7/widgets.js" type="text/javascript"></script>
    <script src="@widget" type="text/javascript"></script>
}
